package com.zzq.my.jetpacks.jectpackapp.ui.act

import android.util.Log
import android.widget.Toast
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.wuyr.activitymessenger.get
import com.wuyr.activitymessenger.startActivity
import com.wuyr.activitymessenger.startActivityForResult
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.databinding.ActivityMessengerBinding

/**
 * 描述：ActivityMessenger，借助Kotlin特性，简化Activity之间传参和回调的逻辑代码。
 * 作者：zhuangzeqin
 * 时间: 2022/1/18-17:04
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class ActivityMessengerAct : BaseActivity(R.layout.activity_messenger) {
    private val bindView by viewBinding(ActivityMessengerBinding::bind)

    /**
     * 初始化数据
     */
    override fun initData() {
//        var binding = DataBindingUtil.inflate<ActivityMmkvBinding>(
//            LayoutInflater.from(mContext),
//            R.layout.activity_mmkv,
//            parent,
//            false
//        )
//        val bindView = bindView<ViewDataBinding>(R.layout.activity_mmkv)
    }

    /**
     * 初始化操作
     */
    override fun initView() {

    }

    /**
     * 初始化点击事件操作
     */
    override fun eventOnClick() {
        bindView.stvStartAct.setOnClickListener {
            startActivity<TargetActivity>()
        }
        bindView.stvStartAct2.setOnClickListener {
            startActivity<TargetActivity>(
                "name" to "zhuangzeqin",
                "age" to 33,
                "list" to listOf("a","b","c"))//携带参数（可连续多个键值对）
        }
        bindView.stvStartAct3.setOnClickListener {
            //不携带参数
            startActivityForResult<TargetActivity>{
                if (it == null) {
                    //未成功处理，即（ResultCode != RESULT_OK）
                    Log.d(TAG, "未成功处理，即（ResultCode != RESULT_OK）")
                } else {
                    //处理成功，这里可以操作返回的intent
                    Log.d(TAG, "处理成功，这里可以操作返回的intent ")
                }
            }
        }
        bindView.stvStartAct4.setOnClickListener {
            //不接收resultCode
            startActivityForResult<TargetActivity>( "name" to "zhuangzeqin",
                "age" to 33,
                "list" to listOf("a","b","c")){
                if (it == null) {
                    //未成功处理
                    Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show()
                } else {
                    //处理成功
                    val result = it.get<String>("Result")
                    Log.d(TAG, "initData: $result")
//                    Toast.makeText(this, result, Toast.LENGTH_SHORT).show()
                }
            }

            //        //接收resultCode
//        startActivityForResult2<TestActivity>(
//            "Content" to content //put参数
//        ) { resultCode, intent ->
//            if (resultCode == RESULT_OK) {
//                //处理成功
//                val result = intent.get<String>("Result")
//                editText.setText(result)
//            } else {
//                //未成功处理
//                Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show()
//            }
//        }

        }

    }


}